package cn.agiledata.bank.common.service;

import java.util.Iterator;
import java.util.List;

import org.apache.commons.lang.StringUtils;

import cn.agiledata.bank.common.dao.AccountTemplateInter;
import cn.agiledata.bank.common.dao.ActionTypeTemplate;
import cn.agiledata.bank.common.servlet.InitForString;
import cn.agiledata.bank.hibernateBean.Account;
import cn.agiledata.bank.hibernateBean.ActionType;
import cn.agiledata.bank.hibernateBean.SubAccount;
import cn.agiledata.bank.hibernateBean.Sysbook;
import com.vnv.infrastructure.logic.IPBMgrFactory;

public class OnlinePayService {
	
	public Account getAccountByAccountId(String accountId)  throws Exception{
		AccountTemplateInter at = (AccountTemplateInter)
		IPBMgrFactory.getMgr("accountTemplate");
		return at.getAccountByAccountId(accountId);
	}
	public SubAccount getSubAccountById(String id) throws Exception{
		AccountTemplateInter at = (AccountTemplateInter)
		IPBMgrFactory.getMgr("accountTemplate");
		return at.getSubAccount(id);
	}
	public String getCurrencyTypeById(String id){
		List currencyTypeList = 
			(List)InitForString.dataDictMap.get("CURRENCY");
		String returnStr = "";
		Iterator iter = currencyTypeList.iterator();
		while (iter.hasNext()){
			Sysbook sys = (Sysbook)iter.next();
			if (sys.getId().getListId().equals(id))
				returnStr = sys.getListName();
		}
		return returnStr;
	}
	public List getSubAccountsById(String accountId)throws Exception{
		AccountTemplateInter at = (AccountTemplateInter)
		IPBMgrFactory.getMgr("accountTemplate");
		return at.getSubAccountsByAccountId(accountId);
	}
	public String getIfPay(String pay){
		if ("Y".equals(pay)){
			return "担保";
		}else{
			return "无担保";
		}
	}
	
	public String getEmailOrPhone(Account acc){
		if (StringUtils.isNotEmpty(acc.getEmail()))
			return acc.getEmail();
		else
			return acc.getMobile();
			
	}
	
	public ActionType getActionTypeById(String id)throws Exception{
		ActionTypeTemplate att = (ActionTypeTemplate)
		IPBMgrFactory.getMgr("actionTypeTemplate");
		
		return att.getActionTypeById(Long.parseLong(id));
	}
}
